home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _B0C4D9A345454C1C83EE011687153060 < prev    next >
Encoding:
Text File  |  2002-06-23  |  13.0 KB  |  523 lines

  1. // Copyright (C) 2001-2002 Raven Software
  2. //
  3. #include "g_local.h"
  4.  
  5. //==========================================================
  6.  
  7. /*QUAKED target_give (1 0 0) (-8 -8 -8) (8 8 8)
  8. Gives the activator all the items pointed to.
  9. */
  10. void Use_Target_Give( gentity_t *ent, gentity_t *other, gentity_t *activator ) {
  11.     gentity_t    *t;
  12.     trace_t        trace;
  13.  
  14.     if ( !activator->client ) {
  15.         return;
  16.     }
  17.  
  18.     if ( !ent->target ) {
  19.         return;
  20.     }
  21.  
  22.     memset( &trace, 0, sizeof( trace ) );
  23.     t = NULL;
  24.     while ( (t = G_Find (t, FOFS(targetname), ent->target)) != NULL ) {
  25.         if ( !t->item ) {
  26.             continue;
  27.         }
  28.         Touch_Item( t, activator, &trace );
  29.  
  30.         // make sure it isn't going to respawn or show any events
  31.         t->nextthink = 0;
  32.         trap_UnlinkEntity( t );
  33.     }
  34. }
  35.  
  36. void SP_target_give( gentity_t *ent ) {
  37.     ent->use = Use_Target_Give;
  38. }
  39.  
  40.  
  41. //==========================================================
  42.  
  43. /*QUAKED target_delay (1 0 0) (-8 -8 -8) (8 8 8)
  44. "wait" seconds to pause before firing targets.
  45. "random" delay variance, total delay = delay +/- random seconds
  46. */
  47. void Think_Target_Delay( gentity_t *ent ) {
  48.     G_UseTargets( ent, ent->activator );
  49. }
  50.  
  51. void Use_Target_Delay( gentity_t *ent, gentity_t *other, gentity_t *activator ) {
  52.     ent->nextthink = level.time + ( ent->wait + ent->random * crandom() ) * 1000;
  53.     ent->think = Think_Target_Delay;
  54.     ent->activator = activator;
  55. }
  56.  
  57. void SP_target_delay( gentity_t *ent ) {
  58.     // check delay for backwards compatability
  59.     if ( !G_SpawnFloat( "delay", "0", &ent->wait ) ) {
  60.         G_SpawnFloat( "wait", "1", &ent->wait );
  61.     }
  62.  
  63.     if ( !ent->wait ) {
  64.         ent->wait = 1;
  65.     }
  66.     ent->use = Use_Target_Delay;
  67. }
  68.  
  69.  
  70. //==========================================================
  71.  
  72. /*QUAKED target_score (1 0 0) (-8 -8 -8) (8 8 8)
  73. "count" number of points to add, default 1
  74.  
  75. The activator is given this many points.
  76. */
  77. void Use_Target_Score (gentity_t *ent, gentity_t *other, gentity_t *activator) 
  78. {
  79.     G_AddScore( activator, ent->count );
  80. }
  81.  
  82. void SP_target_score( gentity_t *ent ) 
  83. {
  84.     if ( !ent->count ) 
  85.     {
  86.         ent->count = 1;
  87.     }
  88.  
  89.     ent->use = Use_Target_Score;
  90. }
  91.  
  92.  
  93. //==========================================================
  94.  
  95. /*QUAKED target_print (1 0 0) (-8 -8 -8) (8 8 8) redteam blueteam private
  96. "message"    text to print
  97. If "private", only the activator gets the message.  If no checks, all clients get the message.
  98. */
  99. void Use_Target_Print (gentity_t *ent, gentity_t *other, gentity_t *activator) {
  100.     if ( activator->client && ( ent->spawnflags & 4 ) ) {
  101.         trap_SendServerCommand( activator-g_entities, va("cp \"%s\"", ent->message ));
  102.         return;
  103.     }
  104.  
  105.     if ( ent->spawnflags & 3 ) {
  106.         if ( ent->spawnflags & 1 ) {
  107.             G_TeamCommand( TEAM_RED, va("cp \"%s\"", ent->message) );
  108.         }
  109.         if ( ent->spawnflags & 2 ) {
  110.             G_TeamCommand( TEAM_BLUE, va("cp \"%s\"", ent->message) );
  111.         }
  112.         return;
  113.     }
  114.  
  115.     trap_SendServerCommand( -1, va("cp \"%s\"", ent->message ));
  116. }
  117.  
  118. void SP_target_print( gentity_t *ent ) {
  119.     ent->use = Use_Target_Print;
  120. }
  121.  
  122.  
  123. //==========================================================
  124.  
  125.  
  126. /*QUAKED target_speaker (1 0 0) (-8 -8 -8) (8 8 8) looped-on looped-off global activator
  127. "noise"        wav file to play
  128. "soundSet"    soundset name to use (do not combine with 'noise', ignores all other flags)
  129.  
  130. A global sound will play full volume throughout the level.
  131. Activator sounds will play on the player that activated the target.
  132. Global and activator sounds can't be combined with looping.
  133. Normal sounds play each time the target is used.
  134. Looped sounds will be toggled by use functions.
  135. Multiple identical looping sounds will just increase volume without any speed cost.
  136. "wait" : Seconds between auto triggerings, 0 = don't auto trigger
  137. "random"    wait variance, default is 0
  138. "radius"    radius of attenuation
  139. */
  140. void Use_Target_Speaker (gentity_t *ent, gentity_t *other, gentity_t *activator) {
  141.     if (ent->spawnflags & 3) {    // looping sound toggles
  142.         if (ent->s.loopSound)
  143.             ent->s.loopSound = 0;    // turn it off
  144.         else
  145.             ent->s.loopSound = ent->noise_index;    // start it
  146.     }else {    // normal sound
  147.         if ( ent->spawnflags & 8 ) {
  148.             G_AddEvent( activator, EV_GENERAL_SOUND, ent->noise_index );
  149.         } else if (ent->spawnflags & 4) {
  150.             G_AddEvent( ent, EV_GLOBAL_SOUND, ent->noise_index );
  151.         } else {
  152.             G_AddEvent( ent, EV_GENERAL_SOUND, ent->noise_index );
  153.         }
  154.     }
  155. }
  156.  
  157. void SP_target_speaker( gentity_t *ent ) 
  158. {
  159.     char    buffer[MAX_QPATH];
  160.     char    *s;
  161.     float    radius;
  162.  
  163.     if ( G_SpawnString ( "soundSet", "", &s ) )
  164.     {    // this is a sound set
  165.         ent->s.mSoundSet = G_AmbientSoundSetIndex(s);
  166.         ent->s.eFlags = EF_PERMANENT;
  167.         VectorCopy( ent->s.origin, ent->s.pos.trBase );
  168.         trap_LinkEntity( ent );
  169.         return;
  170.     }
  171.  
  172.     if ( !G_SpawnString( "noise", "NOSOUND", &s ) ) 
  173.     {
  174. //        G_Error( "target_speaker without a noise key at %s", vtos( ent->s.origin ) );
  175.         G_FreeEntity( ent );
  176.         return;
  177.     }
  178.  
  179.     G_SpawnFloat( "wait", "0", &ent->wait );
  180.     G_SpawnFloat( "random", "0", &ent->random );
  181.     G_SpawnFloat ( "radius", "0", &radius );
  182.  
  183.     // Simple conversion to an integer
  184.     ent->s.time2 = (int) (radius * 1000.0f);
  185.  
  186.     // force all client reletive sounds to be "activator" speakers that
  187.     // play on the entity that activates it
  188.     if ( s[0] == '*' ) {
  189.         ent->spawnflags |= 8;
  190.     }
  191.  
  192.     if (!strstr( s, ".wav" )) {
  193.         Com_sprintf (buffer, sizeof(buffer), "%s.wav", s );
  194.     } else {
  195.         Q_strncpyz( buffer, s, sizeof(buffer) );
  196.     }
  197.     ent->noise_index = G_SoundIndex(buffer);
  198.  
  199.     // a repeating speaker can be done completely client side
  200.     ent->s.eType = ET_SPEAKER;
  201.     ent->s.eventParm = ent->noise_index;
  202.     ent->s.frame = ent->wait * 10;
  203.     ent->s.clientNum = ent->random * 10;
  204.  
  205.  
  206.     // check for prestarted looping sound
  207.     if ( ent->spawnflags & 1 ) {
  208.         ent->s.loopSound = ent->noise_index;
  209.     }
  210.  
  211.     ent->use = Use_Target_Speaker;
  212.  
  213.     if (ent->spawnflags & 4) {
  214.         ent->r.svFlags |= SVF_BROADCAST;
  215.     }
  216.  
  217.     VectorCopy( ent->s.origin, ent->s.pos.trBase );
  218.  
  219.     // must link the entity so we get areas and clusters so
  220.     // the server can determine who to send updates to
  221.     trap_LinkEntity( ent );
  222. }
  223.  
  224.  
  225.  
  226. //==========================================================
  227.  
  228. /*QUAKED target_laser (0 .5 .8) (-8 -8 -8) (8 8 8) START_ON
  229. When triggered, fires a laser.  You can either set a target or a direction.
  230. */
  231. void target_laser_think (gentity_t *self) {
  232.     vec3_t    end;
  233.     trace_t    tr;
  234.     vec3_t    point;
  235.  
  236.     // if pointed at another entity, set movedir to point at it
  237.     if ( self->enemy ) {
  238.         VectorMA (self->enemy->s.origin, 0.5, self->enemy->r.mins, point);
  239.         VectorMA (point, 0.5, self->enemy->r.maxs, point);
  240.         VectorSubtract (point, self->s.origin, self->movedir);
  241.         VectorNormalize (self->movedir);
  242.     }
  243.  
  244.     // fire forward and see what we hit
  245.     VectorMA (self->s.origin, 2048, self->movedir, end);
  246.  
  247.     trap_Trace( &tr, self->s.origin, NULL, NULL, end, self->s.number, CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_CORPSE);
  248.  
  249.     if ( tr.entityNum ) {
  250.         // hurt it if we can
  251.         G_Damage ( &g_entities[tr.entityNum], self, self->activator, self->movedir, 
  252.             tr.endpos, self->damage, DAMAGE_NO_KNOCKBACK, MOD_TARGET_LASER, HL_NONE );
  253.     }
  254.  
  255.     VectorCopy (tr.endpos, self->s.origin2);
  256.  
  257.     trap_LinkEntity( self );
  258.     self->nextthink = level.time + FRAMETIME;
  259. }
  260.  
  261. void target_laser_on (gentity_t *self)
  262. {
  263.     if (!self->activator)
  264.         self->activator = self;
  265.     target_laser_think (self);
  266. }
  267.  
  268. void target_laser_off (gentity_t *self)
  269. {
  270.     trap_UnlinkEntity( self );
  271.     self->nextthink = 0;
  272. }
  273.  
  274. void target_laser_use (gentity_t *self, gentity_t *other, gentity_t *activator)
  275. {
  276.     self->activator = activator;
  277.     if ( self->nextthink > 0 )
  278.         target_laser_off (self);
  279.     else
  280.         target_laser_on (self);
  281. }
  282.  
  283. void target_laser_start (gentity_t *self)
  284. {
  285.     gentity_t *ent;
  286.  
  287.     self->s.eType = ET_BEAM;
  288.  
  289.     if (self->target) 
  290.     {
  291.         ent = G_Find (NULL, FOFS(targetname), self->target);
  292.         if (!ent) 
  293.         {
  294.             Com_Printf ("%s at %s: %s is a bad target\n", self->classname, vtos(self->s.origin), self->target);
  295.         }
  296.         self->enemy = ent;
  297.     } 
  298.     else 
  299.     {
  300.         G_SetMovedir (self->s.angles, self->movedir);
  301.     }
  302.  
  303.     self->use = target_laser_use;
  304.     self->think = target_laser_think;
  305.  
  306.     if ( !self->damage ) 
  307.     {
  308.         self->damage = 1;
  309.     }
  310.  
  311.     if (self->spawnflags & 1)
  312.     {
  313.         target_laser_on (self);
  314.     }
  315.     else
  316.     {
  317.         target_laser_off (self);
  318.     }
  319. }
  320.  
  321. void SP_target_laser (gentity_t *self)
  322. {
  323.     // let everything else get spawned before we start firing
  324.     self->think = target_laser_start;
  325.     self->nextthink = level.time + FRAMETIME;
  326. }
  327.  
  328.  
  329. //==========================================================
  330.  
  331. void target_teleporter_use( gentity_t *self, gentity_t *other, gentity_t *activator ) 
  332. {
  333.     gentity_t    *dest;
  334.  
  335.     if (!activator->client)
  336.     {
  337.         return;
  338.     }
  339.     
  340.     dest =     G_PickTarget( self->target );
  341.     if (!dest) 
  342.     {
  343.         Com_Printf ("Couldn't find teleporter destination\n");
  344.         return;
  345.     }
  346.  
  347.     TeleportPlayer( activator, dest->s.origin, dest->s.angles );
  348. }
  349.  
  350. /*QUAKED target_teleporter (1 0 0) (-8 -8 -8) (8 8 8)
  351. The activator will be teleported away.
  352. */
  353. void SP_target_teleporter( gentity_t *self ) {
  354.     if (!self->targetname)
  355.         Com_Printf("untargeted %s at %s\n", self->classname, vtos(self->s.origin));
  356.  
  357.     self->use = target_teleporter_use;
  358. }
  359.  
  360. //==========================================================
  361.  
  362.  
  363. /*QUAKED target_relay (.5 .5 .5) (-8 -8 -8) (8 8 8) RED_ONLY BLUE_ONLY RANDOM
  364. This doesn't perform any actions except fire its targets.
  365. The activator can be forced to be from a certain team.
  366. if RANDOM is checked, only one of the targets will be fired, not all of them
  367. */
  368. void target_relay_use (gentity_t *self, gentity_t *other, gentity_t *activator) 
  369. {
  370.     if ( ( self->spawnflags & 1 ) && activator->client 
  371.         && activator->client->sess.team != TEAM_RED ) 
  372.     {
  373.         return;
  374.     }
  375.     if ( ( self->spawnflags & 2 ) && activator->client 
  376.         && activator->client->sess.team != TEAM_BLUE ) {
  377.         return;
  378.     }
  379.     if ( self->spawnflags & 4 ) {
  380.         gentity_t    *ent;
  381.  
  382.         ent = G_PickTarget( self->target );
  383.         if ( ent && ent->use ) {
  384.             ent->use( ent, self, activator );
  385.         }
  386.         return;
  387.     }
  388.     G_UseTargets (self, activator);
  389. }
  390.  
  391. void SP_target_relay (gentity_t *self) {
  392.     self->use = target_relay_use;
  393. }
  394.  
  395.  
  396. //==========================================================
  397.  
  398. /*QUAKED target_kill (.5 .5 .5) (-8 -8 -8) (8 8 8)
  399. Kills the activator.
  400. */
  401. void target_kill_use( gentity_t *self, gentity_t *other, gentity_t *activator ) 
  402. {
  403.     G_Damage ( activator, NULL, NULL, NULL, NULL, 100000, DAMAGE_NO_PROTECTION, MOD_TELEFRAG, HL_NONE );
  404. }
  405.  
  406. void SP_target_kill( gentity_t *self ) {
  407.     self->use = target_kill_use;
  408. }
  409.  
  410. /*QUAKED target_position (0 0.5 0) (-4 -4 -4) (4 4 4)
  411. Used as a positional target for in-game calculation, like jumppad targets.
  412. */
  413. void SP_target_position( gentity_t *self ){
  414.     G_SetOrigin( self, self->s.origin );
  415. }
  416.  
  417. static void target_location_linkup(gentity_t *ent)
  418. {
  419.     int i;
  420.     int n;
  421.  
  422.     if (level.locationLinked) 
  423.         return;
  424.  
  425.     level.locationLinked = qtrue;
  426.  
  427.     level.locationHead = NULL;
  428.  
  429.     trap_SetConfigstring( CS_LOCATIONS, "unknown" );
  430.  
  431.     for ( i = 0, ent = g_entities, n = 1;
  432.           i < level.num_entities;
  433.           i++, ent++) 
  434.     {
  435.         if (ent->classname && !Q_stricmp(ent->classname, "target_location")) 
  436.         {
  437.             // lets overload some variables!
  438.             ent->health = n; // use for location marking
  439.  
  440.             trap_SetConfigstring( CS_LOCATIONS + n, ent->message );
  441.             n++;
  442.             ent->nextTrain = level.locationHead;
  443.             level.locationHead = ent;
  444.         }
  445.     }
  446.  
  447.     // All linked together now
  448. }
  449.  
  450. /*QUAKED target_location (0 0.5 0) (-8 -8 -8) (8 8 8)
  451. Set "message" to the name of this location.
  452.  
  453. Closest target_location in sight used for the location, if none
  454. in site, closest in distance
  455. */
  456. void SP_target_location( gentity_t *self )
  457. {
  458.     self->think = target_location_linkup;
  459.     self->nextthink = level.time + 200;  // Let them all spawn first
  460.  
  461.     G_SetOrigin( self, self->s.origin );
  462. }
  463.  
  464. /*QUAKED target_effect (0 0.5 0) (-8 -8 -8) (8 8 8)
  465. Plays an effect each time its targetted
  466.  
  467. "effect"  effect to play
  468. "delay"      delay in milliseconds before the effect plays
  469. */
  470.  
  471. void target_effect_delayed_use ( gentity_t* self )
  472. {
  473.     G_PlayEffect( self->health, self->s.origin, self->pos1 );
  474.  
  475.     self->nextthink = 0;
  476. }
  477.  
  478. void target_effect_use (gentity_t *self, gentity_t *other, gentity_t *activator)
  479. {
  480.     if ( self->count )
  481.     {
  482.         self->think = target_effect_delayed_use;
  483.         self->nextthink = level.time + self->count;
  484.     }
  485.     else
  486.     {
  487.         target_effect_delayed_use ( self );
  488.     }
  489. }
  490.  
  491. void SP_target_effect ( gentity_t *ent )
  492. {
  493.     char        *effectName;
  494.     gentity_t    *target;
  495.  
  496.     G_SetOrigin( ent, ent->s.origin );
  497.  
  498.     G_SpawnString ( "effect", "", &effectName );
  499.     ent->health = G_EffectIndex(effectName);
  500.  
  501.     // See if they want it delayed a bit
  502.     G_SpawnInt ( "delay", "0", &ent->count );
  503.  
  504.     target = G_Find(0, FOFS(targetname), ent->target);
  505.     if (target)
  506.     {
  507.         VectorSubtract( target->s.origin, ent->s.origin, ent->pos1 );
  508.         VectorNormalize( ent->pos1 );
  509.         // find angles
  510.         vectoangles( ent->pos1, ent->r.currentAngles );
  511.         // copy over to other angles
  512.         VectorCopy( ent->r.currentAngles, ent->s.angles );    
  513.         VectorCopy( ent->r.currentAngles, ent->s.apos.trBase );
  514.     }
  515.     else
  516.     {
  517.         ent->pos1[0] = ent->pos1[1] = 0.0;
  518.         ent->pos1[2] = 1.0;
  519.     }
  520.  
  521.     ent->use = target_effect_use;
  522. }
  523.